/*
    城镇非住宅：town-Non-residential
    城镇住宅：town-residential
    农村公共建筑：country-publicbuilding
    农村住宅：country-residential
     */
function initTMapGetIconByType(buildtype,sptype) {

    var icon = new TIcon("/static/app/fwsjcj/taskmanage/image/town-Non-residential01.png", new TSize(16, 16), {anchor: new TPixel(10, 14)});
    if (buildtype == 1) {
        if(sptype==0){
            icon = new TIcon("/static/app/fwsjcj/taskmanage/image/town-Non-residential03.png", new TSize(16, 16), {anchor: new TPixel(10, 14)});
        }else if(sptype==1){
            icon = new TIcon("/static/app/fwsjcj/taskmanage/image/town-Non-residential02.png", new TSize(16, 16), {anchor: new TPixel(10, 14)});
        }else if(sptype==2){
            icon = new TIcon("/static/app/fwsjcj/taskmanage/image/town-Non-residential01.png", new TSize(16, 16), {anchor: new TPixel(10, 14)});
        }else if(sptype==3){
            icon = new TIcon("/static/app/fwsjcj/taskmanage/image/town-Non-residential04.png", new TSize(16, 16), {anchor: new TPixel(10, 14)});
        }
    } else if (buildtype == 0) {
        if(sptype==0){
            icon = new TIcon("/static/app/fwsjcj/taskmanage/image/town-residential03.png", new TSize(16, 16), {anchor: new TPixel(10, 14)});
        }else if(sptype==1){
            icon = new TIcon("/static/app/fwsjcj/taskmanage/image/town-residential02.png", new TSize(16, 16), {anchor: new TPixel(10, 14)});
        }else if(sptype==2){
            icon = new TIcon("/static/app/fwsjcj/taskmanage/image/town-residential01.png", new TSize(16, 16), {anchor: new TPixel(10, 14)});
        }else if(sptype==3){
            icon = new TIcon("/static/app/fwsjcj/taskmanage/image/town-residential04.png", new TSize(16, 16), {anchor: new TPixel(10, 14)});
        }
    } else if (buildtype == 2) {
        if(sptype==0){
            icon = new TIcon("/static/app/fwsjcj/taskmanage/image/country-publicbuilding03.png", new TSize(16, 16), {anchor: new TPixel(10, 14)});
        }else if(sptype==1){
            icon = new TIcon("/static/app/fwsjcj/taskmanage/image/country-publicbuilding02.png", new TSize(16, 16), {anchor: new TPixel(10, 14)});
        }else if(sptype==2){
            icon = new TIcon("/static/app/fwsjcj/taskmanage/image/country-publicbuilding01.png", new TSize(16, 16), {anchor: new TPixel(10, 14)});
        }else if(sptype==3){
            icon = new TIcon("/static/app/fwsjcj/taskmanage/image/country-publicbuilding04.png", new TSize(16, 16), {anchor: new TPixel(10, 14)});
        }
    } else if (buildtype == 3) {
        if(sptype==0){
            icon = new TIcon("/static/app/fwsjcj/taskmanage/image/country-residential03.png", new TSize(16, 16), {anchor: new TPixel(10, 14)});
        }else if(sptype==1){
            icon = new TIcon("/static/app/fwsjcj/taskmanage/image/country-residential02.png", new TSize(16, 16), {anchor: new TPixel(10, 14)});
        }else if(sptype==2){
            icon = new TIcon("/static/app/fwsjcj/taskmanage/image/country-residential01.png", new TSize(16, 16), {anchor: new TPixel(10, 14)});
        }else if(sptype==3){
            icon = new TIcon("/static/app/fwsjcj/taskmanage/image/country-residential04.png", new TSize(16, 16), {anchor: new TPixel(10, 14)});
        }
    }
    return icon;
}

var staticDataMarkerLayer = [];
var staticDataLabelLayer = [];
function initTMapAddMarkLabelArray(map,fwinfo,point,name, icon) {
    if (point != null && icon != null) {
        //有图标地址
        //根据经纬度、文本、图标icon，建立图标
        var marker = new TMarker(new TLngLat(point[0], point[1]), {icon: icon});
        //判断是否有任务名称
        if (name != null) {
            var title = name;
            marker.setTitle(title);
        } else {
            marker.setTitle("未命名");
        }
        //添加图标
        map.addOverLay(marker);
        staticDataMarkerLayer.push(marker);

        var label = initTMapAddMarkText(point, name, -20, "black");
        //添加文字
        map.addOverLay(label);
        staticDataLabelLayer.push(label);

    }
}

function clearStatisticalFWDatas(map) {
    debugger;
    for(var i=0;i<staticDataMarkerLayer.length;i++){
        map.removeOverLay(staticDataMarkerLayer[i]);
    }
    for(var i=0;i<staticDataLabelLayer.length;i++){
        map.removeOverLay(staticDataLabelLayer[i]);
    }
    staticDataMarkerLayer=[];
    staticDataMarkerLayer.length=0;
    staticDataLabelLayer=[];
    staticDataLabelLayer.length=0;
}

function initTMapAddMarkText(lonlat, imgText, yOffset, fontColor) {
    //新建图标文字
    var configText = {
        offset: new TPixel(-25, yOffset),
        position: new TLngLat(lonlat[0], lonlat[1])
    };
    var label = new TLabel(configText);
    label.setLabel(imgText);//文本内容
    label.setTitle(imgText);//提示信息
    label.setBackgroundColor("white");//背景色
    label.setBorderColor("gray");//边框颜色
    label.setBorderLine(1);//边框线宽
    label.setNoWrap(true);//允许换行
    label.setFontSize(12);//文本字体大小
    label.setFontColor(fontColor);//文本字体颜色
    label.setOpacity(1);//设置透明度

    return label;
}

function initPointInsidePolygon(pointsArray, LonLat) {
    var bool = false;//点不在面内
    if (LonLat != null) {
        var x = LonLat[0];
        var y = LonLat[1];
        var length = pointsArray.length;
        for (var i = 0, j = length - 1; i < length; j = i++) {
            var xi = pointsArray[i][0];
            var yi = pointsArray[i][1];
            var xj = pointsArray[j][0];
            var yj = pointsArray[j][1];
            var intersect = ((yi > y) != (yj > y))
                && (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
            if (intersect) {
                bool = !bool;
            }
        }
    }
    return bool;
}

function lnglatdataswitch(points){
    var points1=[];
    if (points != null && points.length > 0) {
        for (var i = 0; i < points.length; i++) {
            var pp = [];
            pp.push(parseFloat(points[i].getLng()));
            pp.push(parseFloat(points[i].getLat()));
            points1.push(pp);
        }
    }
    return points1;
}

function initShowContextMenu(str, type, x, y) {
    //设置右键菜单位置
    var left = x;
    //获取右键菜单位置left最大值
    var maxLeft = $("body").width() - ($(str + "-leftContextMenuDiv").width() + 1);
    if (left > maxLeft) {
        left = maxLeft;
    }

    var top = y - $(str + "-mapDiv").offset().top;
    //获取右键菜单位置top最大值
    var maxTop = $("body").height() - ($(str + "-leftContextMenuDiv").height() + 1);
    if (top > maxTop) {
        top = maxTop;
    }
    if (type == 1) {
        $(str + "-contextMenuDiv").css("left", left + "px");
        $(str + "-contextMenuDiv").css("top", top+40 + "px");
        $(str + "-contextMenuDiv").show();
    } else if (type == 2) {
        $(str + "Ex-contextMenuDiv").css("left", left + "px");
        $(str + "Ex-contextMenuDiv").css("top", top+40 + "px");
        $(str + "Ex-contextMenuDiv").show();
    } else if (type == 3) {
        $(str + "FW-contextMenuDiv").css("left", left + "px");
        $(str + "FW-contextMenuDiv").css("top", top+80 + "px");
        $(str + "FW-contextMenuDiv").show();
    }
}